<!DOCTYPE html>
<html>
<head>
  #include('head.html',{title:'APP更新'})
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>
          <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
        </div>
        
        <table id="LAY-update-manage" lay-filter="LAY-update-manage"></table>

        <script type="text/html" id="table-useradmin-webuser">
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
      </div>
    </div>
  </div>

  <script src="/layuiadmin/layui/layui.js"></script>
  <script>
  layui.config({
    base: '/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'useradmin', 'table'], function(){
    var $ = layui.$
    ,form = layui.form
    ,table = layui.table;
    
    //监听搜索
    form.on('submit(LAY-front-search)', function(data){
      var field = data.field;
        field.page = 1;
      
      //执行重载
      table.reload('LAY-update-manage', {
        where: field
      });
    });
  
    //事件
    var active = {
      batchdel: function(){
        var checkStatus = table.checkStatus('LAY-update-manage')
        ,checkData = checkStatus.data, //得到选中的数据
        ids = [];

        if(checkData.length === 0){
          return layer.msg('请选择数据');
        }
        for (var i in checkData) {
            ids.push(checkData[i].uId);
        }
        layer.prompt({
          formType: 1
          ,title: '敏感操作，请验证密码'
        }, function(value, index) {
            if (checkpass(value)) {
                layer.close(index);
                layer.confirm('确定删除吗？', function (index) {
                    $.ajax({
                        url: "delUpdate",
                        dataType: "json",
                        type: "post",
                        data: {
                            ids: ids
                        },
                        success: function (data) {
                            if (data.status == 1) {
                                layer.msg('删除成功', {
                                    icon: 1
                                    , time: 1000
                                }, function () {
                                    table.reload('LAY-update-manage');
                                });
                            }
                            else if (data.status == 0) {
                                layer.msg('删除失败', {
                                    icon: 0
                                    , time: 1000
                                });
                            }
                        },
                        error: function (result) {
                            console.log(result);
                            alert("系统繁忙！");
                        }
                    });
                });
            }
        });
      }
      ,add: function(){
        var index = layer.open({
          type: 2
          ,title: '发布更新'
          ,content: 'updateAdd'
          ,maxmin: true
          ,area: ['500px', '450px']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            var iframeWindow = window['layui-layer-iframe'+ index]
            ,submitID = 'LAY-front-submit'
            ,submit = layero.find('iframe').contents().find('#'+ submitID);


            submit.trigger('click');
          }
        });
        //如果手机端，全屏显示
        if(window.innerWidth <= 768) {
            layui.layer.full(index);
            setTimeout(function () {
                layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                    tips: 3
                });
            }, 500)
        }
      }
    };
    
    $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  </script>
</body>
</html>
